package ;

import cmtc.app.brtcheck.db.dfi.Garage;
import cmtc.app.brtcheck.db.pcheck.Measure;
import cmtc.app.brtcheck.db.pcheck.MeasureNotPassed;
import haxe.Serializer;
//import cmtc.app.brtcheck.db.pcheck.Measure;
import cmtc.app.brtcheck.db.Type;
import cmtc.viz.source.query.Query;
import cmtc.app.brtcheck.db.Line;
import flash.Lib;

/**
 * ...
 * @author waneck
 */

class Main 
{
	
	static function main() 
	{
		trace("Hello, World!");
		trace(Serializer.run( { teste:"campo", array:[1, 2, 3, 4, 5] } ));
		
		trace(Query.make(Q.uery(Measure).instance.ID));
		trace(Query.make(Q.uery(MeasureNotPassed).instance.contingency.cod == "Meu Codigo"));
		trace(Query.make(Q.uery(Measure).instance.ID >= 10));
		trace(Query.make(Q.uery(Garage).instance.cod != "teste"));
		trace(Query.make(((Q.uery(Line).instance.typeRel.description)) == "MyDescription"));
		trace(Query.make((Q.uery(Line).instance.typeRel.description == "MyDescription") && (Q.uery(Line).instance.typeRel.description == "MyDescription")));
		trace(Query.make((Q.uery(Line).instance.typeRel.description == "MyDescription") || (Q.uery(Line).instance.typeRel.description == "MyDescription")));
		
		trace(Q.uery(Garage).cod.query(Constraint.Equal(QueryValue.QString("teste"))));
		
		/*Query.make({
			function(q:Measure)
			{
				//var q = Q.uery(Measure).instance;
				var q2 = q.passedInstance.values().orderBy("ID").last();
				return ((q2.measure.get().status.ID == 1 || q2.measure.get().status.ID == 2) && (( (Std.is(q2, MeasurePassed) && q2.action.ID == 3)) || q2.action.ID == 4));
			}
		});*/
		Query.filter(Measure, {Measure.status.cod == "1" || Measure.status.ID == 2});
		select * from Measure As q1 left join status as q2 on status.ID = measure.status where q2.cod = "1" or q2.id = 2;
		
		Query.make({
			var q = Query.make(Measure.passedInstances).orderBy(id).last();
			if (q.measure.status == Status.Passed || q.measure.status == Status.NotPassed) && (q.action == Action.Something || q.action == Action.SomethingElse) return q.measure;
		});
		select * from (select MeasureNotPassed.* from Measure as t1, MeasureNotPassed left join Measure as t2 ON t1.id = t2.id AND t1.) as t where t.
		//Query.make()
		/*
		var q2 = Measure.passedInstances.last();
		var q = 
		*/
		
		//var q1 = Query.make(Q.uery(Measure).instance.passedInstance).map(function(m:))
		
		//var q = Measure.query(function(m:Measure):Array<MeasureNotPassed> {return m.passedInstance;}).map(function(a:Array<Array<MeasureNotPassed>>) return a[])
	}
	
}